package com.camel.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.camel.base.mapper.TbDictValueMapper;
import com.camel.base.model.TbDictValue;
import com.camel.base.service.TbDictValueService;
import com.camel.core.service.AbstractBaseCommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 86183
 * @description 针对表【tb_dict_value】的数据库操作Service实现
 * @createDate 2023-08-16 10:42:03
 */
@Service
public class TbDictValueServiceImpl extends AbstractBaseCommonService<TbDictValueMapper, TbDictValue> implements TbDictValueService<TbDictValue> {


    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @Override
    public TbDictValue selectEnumWithRedis(Integer typeId, String val) {
        Jackson2JsonRedisSerializer<TbDictValue> jsonRedisSerializer = new Jackson2JsonRedisSerializer<>(TbDictValue.class);
        TbDictValue value = getOne(new QueryWrapper<TbDictValue>().eq("dict_id", typeId).eq("dict_val", val));
        ValueOperations<String, String> stringStringValueOperations = redisTemplate.opsForValue();
        stringStringValueOperations.set("dict" + typeId, new String(jsonRedisSerializer.serialize(value)));
        String s = stringStringValueOperations.get("dict" + typeId);
        byte[] bytes = s.getBytes();
        TbDictValue deserialize = jsonRedisSerializer.deserialize(bytes);
        System.out.println(deserialize);
        return value;
    }
}




